package com.ds.api.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;

import com.google.gson.Gson;

/**
 * 统一异常处理
 * @className: BaseController
 * @description: TODO
 * @author xiangwei
 */
public class BaseController {
    
    private static final Logger log = LoggerFactory
            .getLogger(BaseController.class);
    @ExceptionHandler  
    public void exp(HttpServletRequest request, HttpServletResponse response, Exception ex)  {  
        Map<String, Object> result = new HashMap<String, Object>();

        result.put("result","1");
        result.put("err_str","网络错误请联系我们");

        Gson gson = new Gson();
        response.setCharacterEncoding("utf-8");
        ex.printStackTrace();
        try {
            response.getWriter().println(gson.toJson(result));
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}